home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / Game.EXE_01_2001.iso / demos / Blade of Darkness / data1.cab / Program_Executable_Files / Lib / NetTraps.py < prev    next >
Encoding:
Python Source  |  2000-11-16  |  5.7 KB  |  221 lines

  1. import netgame
  2. import Bladex
  3. import LavaDefDamage
  4. import Netval
  5. import math
  6. import NetMisc
  7. import dust
  8. import whrandom
  9. import Sounds
  10. import Actions
  11.  
  12. def rand(time):
  13.     PRIME = 123457
  14.     MULTI = 510510
  15.     
  16.     return (1.0*((MULTI*time)%PRIME))/PRIME
  17.  
  18. def CPrime(min):
  19.     p = [2,3,5,7,11]
  20.     c = 12
  21.     
  22.     while p[len(p)-1]<min:
  23.         c = c + 1
  24.         ip = 1
  25.         for v in p:
  26.             if c % v==0:
  27.                 ip = 0
  28.                 break
  29.         if ip:
  30.             p.append(c)
  31.             print c
  32.             
  33.             
  34. StartTime   = 0.0                     # Variable global que marca el inicio de un round
  35. ListOfTraps = []                    # Lista de trampas en el juego
  36.  
  37. def LeeCadena(id,type,cad):
  38.     global StartTime
  39.     
  40.     if type ==  Netval.NET_GAME_START_TRAPS:
  41.         StartTime = float(cad)
  42.  
  43.     for o in ListOfTraps:
  44.         o.Start()
  45.     
  46.  
  47. NetMisc.LReadUserString.append(LeeCadena)
  48.  
  49. def IniciaRound():
  50.     global StartTime
  51.  
  52.     StartTime           = netgame.GetTime()
  53.     netgame.SendUserString(Netval.NET_GAME_START_TRAPS,`StartTime`)
  54.  
  55.     for o in ListOfTraps:
  56.         o.Start()
  57.  
  58.  
  59. NetMisc.LOnStartRoundFunc.append(IniciaRound)
  60.  
  61. #################### TRAMPA DE LA LAVA ####################
  62. class LavaFlood:
  63.     TimeRound  = 3
  64.     DeltaRound = 5000
  65.     Quake      = 0
  66.     sino       = 0
  67.     
  68.     def QuemarCliente(self,entid):
  69.         namex = entid.Name+"LavaFire"
  70.         wps = Bladex.GetEntity(namex)
  71.         if netgame.GetPlayerData(entid.Name)[1] <= 0:
  72.             if not entid.Data.LavaDeath:
  73.                 Actions.FireDeath(entid.Name)
  74.                 entid.Data.LavaDeath = 1            
  75.         else:
  76.             entid.Data.LavaDeath = 0
  77.             if wps:
  78.                 wps.Position = entid.Position[0], self.Surface.Position[1]+1, entid.Position[2]
  79.             else:
  80.                 wps=Bladex.CreateEntity(namex, "Entity Particle System D1", entid.Position[0], self.Surface.Position[1]+1, entid.Position[2])
  81.                 wps.ParticleType="LargeFire"
  82.                 wps.Time2Live=16
  83.                 wps.RandomVelocity=10.0
  84.                 wps.Velocity=0,-1000,0
  85.                 wps.YGravity=0
  86.                 wps.PPS=50
  87.     
  88.             
  89.             wps.DeathTime=Bladex.GetTime()+1.0
  90.  
  91.     def __init__(self,Max,Min,MaxT,MinT,text="cala2"):
  92.         global ListOfTraps
  93.         
  94.         self.Max      = Max
  95.         self.Min      = Min
  96.         self.MaxT     = MaxT
  97.         self.MinT     = MinT
  98.         self.Surface  = None
  99.         self.Texture  = text
  100.         
  101.         ListOfTraps.append(self)
  102.  
  103.     # check for lava values on lineX
  104.     def TestLavaDamage(self,ent):
  105.         if ent.Position[1]+1500 > self.Surface.Position[1]:
  106.             print ent.Name," se quema de lo lindo."
  107.             self.QuemarCliente(ent)
  108.             return 1
  109.         return 0
  110.  
  111.     def Start(self):
  112.         global StartTime
  113.         
  114.         if not self.Surface:
  115.             self.LavaName     = "Lava"+Bladex.GenerateEntityName()
  116.             print "Creating '"+self.LavaName+"' for fun"
  117.             self.LavaDamage   = LavaDefDamage.LAVA_AREA()
  118.             self.LavaDamage.CreateLava (self.LavaName,self.Position[0],self.Position[1],self.Position[2], self.Texture, 0.01 )
  119.             self.Surface      = Bladex.GetEntity(self.LavaName)
  120.             NetMisc.LOnDamageFunc.append(self.TestLavaDamage)
  121.                         
  122.         
  123.         self.Surface.TimerFunc   = self.floodTimer        
  124.         self.Surface.SubscribeToList("Timer30")
  125.                 
  126.         self.MaxTime = (self.MaxT-self.MinT)*rand(StartTime) + self.MinT
  127.     
  128.     def floodTimer(self,ent, time):
  129.            global StartTime
  130.  
  131.         time = netgame.GetTime()
  132.         
  133.         tetha = (time-StartTime)/self.MaxTime
  134.         
  135.         tetha = abs(((tetha+1)%2)-1)
  136.         
  137.         sino = time/self.TimeRound
  138.         AddSin = math.sin(3.1515*sino)*self.DeltaRound
  139.         
  140.         pos = (self.Max-self.Min)*tetha+self.Min + AddSin
  141.         
  142.         self.Surface.Position = self.Position[0], pos, self.Position[2]
  143.         
  144.         if self.Quake:
  145.             if sino > self.sino+2.0:
  146.                 temblOn(0)
  147.                 self.sino = int(sino/2)*2
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. #################### Temblores Aleatorios ####################
  155.  
  156. mQuakeTime     = 2
  157. MQuakeTime     = 4
  158.  
  159. mQuakeDelay    = 5
  160. MQuakeDelay    = 10
  161.  
  162. QuakeIntensity = 100
  163.  
  164. Temblon_ = [1,1,1]
  165.  
  166. Temblon_[0]=Sounds.CreateEntitySound("..\\..\\Sounds\\terremoto-piedras.wav","desprendimiento1")
  167. Temblon_[0].Volume=1; Temblon_[0].MinDistance=90000; Temblon_[0].MaxDistance=100000; 
  168.  
  169. Temblon_[1]=Sounds.CreateEntitySound("..\\..\\Sounds\\Rock-floor-collapse.wav","desprendimiento2")
  170. Temblon_[1].Volume=1; Temblon_[1].MinDistance=90000; Temblon_[1].MaxDistance=100000; 
  171.  
  172. Temblon_[2]=Sounds.CreateEntitySound("..\\..\\Sounds\\ground-collapse.wav","desprendimiento3")
  173. Temblon_[2].Volume=1; Temblon_[2].MinDistance=90000; Temblon_[2].MaxDistance=100000; 
  174.  
  175.  
  176. def temblOff():
  177.     cam = Bladex.GetEntity("Camera")
  178.     cam.EarthQuakeFactor = 0
  179.     cam.EarthQuake = 0
  180.  
  181. def temblOn(repeat = 1):
  182.     global mQuakeTime
  183.     global MQuakeTime
  184.     global mQuakeDelay
  185.     global MQuakeDelay
  186.     global QuakeIntensity
  187.     
  188.     cam = Bladex.GetEntity("Camera")
  189.     cam.EarthQuakeFactor = QuakeIntensity
  190.     cam.EarthQuake = 1
  191.     Bladex.AddScheduledFunc(Bladex.GetTime()+whrandom.randint(mQuakeTime, MQuakeTime), temblOff,())
  192.     if repeat:
  193.         Bladex.AddScheduledFunc(Bladex.GetTime()+whrandom.randint(mQuakeDelay,MQuakeDelay), temblOn,())
  194.     char= Bladex.GetEntity("Player1")
  195.     m = whrandom.randint(0,2)
  196.     Temblon_[m].Position = char.Position
  197.     Temblon_[m].PlaySound(1)
  198.     
  199.  
  200.  
  201. ######################[ E J E M P L O S ]######################
  202. """
  203. import NetTraps
  204.  
  205. # Agrega una trampa de lava
  206. lava = NetTraps.LavaFlood(-5000,60000,240,120)    # <limite superior>,<limite inferior>,<maximo de tiempo>,<minimo de tiempo>
  207. lava.Position = (26837, 74000, 4427)        # Posicion donde esta la lava
  208. lava.TimeRound  = 4                # Tiempo de oscilacion
  209. lava.DeltaRound = 3000                # Radio de oscilacion
  210. lava.Quake      = 1                # asigna el evento de temblores a la oscilacion.
  211.  
  212. # Temblores
  213. NetTraps.mQuakeTime     =   2            # Duracion minima del temblores
  214. NetTraps.MQuakeTime     =   4            # Duracion maxima del temblores
  215. NetTraps.mQuakeDelay    =   5            # Retardo minimo entre temblores
  216. NetTraps.MQuakeDelay    =  10            # Retardo maximo entre temblores
  217. NetTraps.QuakeIntensity = 100            # Intensidad del temblor
  218.  
  219. NetTraps.temblOn()                # activa los temblores para siempre (no usar si se asigna a la lava)
  220.  
  221. """